package com.ruoyi.huanghefd.controller;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.huanghefd.domain.Worksheet;
import com.ruoyi.huanghefd.domain.WorksheetDh;
import com.ruoyi.huanghefd.service.WorksheetDhService;
import com.ruoyi.huanghefd.service.WorksheetService;
import com.ruoyi.huanghefd.utils.PageBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author gnplum
 * @Date 2023/11/12 17:00
 * @PackageName:com.ruoyi.huanghefd.controller
 * @ClassName: WorksheetDhController
 * @Description: TODO
 * @Version 1.0
 */
@RestController
@RequestMapping("/huanghefd")
public class WorksheetDhController {
    private static final Logger log = LoggerFactory.getLogger(WorksheetDhController.class);

    @Resource
    private WorksheetDhService worksheetDhService;

    /**
     * @Author gnplum
     * @Description //新增工作票
     * @Date 9:48 2023/10/31
     * @param worksheetDh
     * @return com.ruoyi.huanghefd.domain.ResultWS
     * http://localhost:8080/huanghefd/addWorksheet
     **/
    @PostMapping("/addWorksheetDH")
    public AjaxResult addWorksheetDH(@RequestBody WorksheetDh worksheetDh){
        log.info(">> 新增动火工作票-入参==" + JSON.toJSONString(worksheetDh));
        AjaxResult ajax = worksheetDhService.addWorksheetDh(worksheetDh);
        log.info("<< 新增动火工作票-返回==" + ajax.toString());
        return ajax;
    }

    /**
     * @Author gnplum
     * @Description //删除工作票
     * @Date 15:22 2023/10/31
     * @param dhCode
     * @return com.ruoyi.common.core.domain.AjaxResult
     * http://localhost:8080/huanghefd/delWorksheet?wsId=4e60df22773811eeb08e00e04c738ae4
     **/
    @PostMapping(value = "/delWorksheetDH")
    public AjaxResult delWorksheetDH(@RequestParam(required = false,value = "dhCode") String dhCode){
        log.info(">> 删除动火票-入参 dhCode==" + dhCode);
        if(dhCode.isEmpty()){
            return AjaxResult.success("请点选要删除的动火票");
        }
        AjaxResult ajax = worksheetDhService.delWorksheetDh(dhCode);
        log.info(">> 删除动火票-返回==" + ajax);
        return ajax;
    }

    /**
     * @Author gnplum
     * @Description //修改动火票
     * @Date 15:47 2023/10/31
     * @param worksheetDh
     * @return com.ruoyi.common.core.domain.AjaxResult
     * http://localhost:8080/huanghefd/uptWorksheet
     **/
    @PostMapping(value = "/uptWorksheetDH")
    public AjaxResult uptWorksheetDH(@RequestBody WorksheetDh worksheetDh){
        log.info(">> 修改动火票-入参 ==" + JSON.toJSONString(worksheetDh));
        AjaxResult ajax = worksheetDhService.uptWorksheetDh(worksheetDh);
        log.info(">> 修改动火票-返回 ==" + ajax);
        return ajax;
    }

    /**
     * @Author gnplum
     * @Description //查询动火票 分页
     * @Date 9:48 2023/10/31
     * @param dhCode,dhDept,dhState
     * @return com.ruoyi.common.core.domain.AjaxResult
     * http://localhost:18080/huanghefd/queryWorksheet?wsCode=20231102000001&wsDept=100
     **/
    @PostMapping(value = "/queryWorksheetDH")
    public PageBean queryWorksheetDhList(@RequestParam(required = false, value = "dhCode") String dhCode, @RequestParam(required = false, value = "dhDept") String dhDept, @RequestParam(required = false, value = "dhState") String dhState, @RequestParam(required = false, value = "userId") String userId, @RequestParam(required = false, value = "mailType") String mailType, @RequestParam(required = false, value = "dhType") String dhType, @RequestParam(value = "pageNum") int pageNum, @RequestParam(value = "pageSize") int pageSize) {
        log.info(">> 查询动火票-入参==" + dhCode + "," + dhDept + "," + dhState + "," + userId + "," + mailType+ "," + dhType);
        PageBean ajax = worksheetDhService.queryWorksheetDhByPage(dhCode, dhDept, dhState, userId, mailType, dhType, pageNum, pageSize);//mailType 1-收件箱 2-发件箱 3-草稿箱
        log.info(">> 查询动火票-返回==" + ajax);
        return ajax;
    }
    @PostMapping(value = "/queryWorksheetDH1")
    public AjaxResult queryWorksheetDhList(@RequestParam(required = false,value = "dhCode") String dhCode, @RequestParam(required = false,value = "dhDept") String dhDept, @RequestParam(required = false,value = "dhState") String dhState, @RequestParam(required = false,value = "userId") String userId, @RequestParam(required = false,value = "mailType") String mailType){
        log.info(">> 查询动火票-入参==" + dhCode + "," + dhDept + "," + dhState + "," + userId + "," + mailType);
        AjaxResult ajax= worksheetDhService.queryWorksheetDhs(dhCode,dhDept,dhState,userId,mailType);//mailType 1-收件箱 2-发件箱 3-草稿箱
        log.info(">> 查询动火票-返回==" + ajax);
        return ajax;
    }
}
